﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Web;
using System.Drawing;
using System.Drawing.Imaging;

/// <summary>
/// C# Display text as Image
/// </summary>
namespace MikeKappel.Com.CS
{
    /// <summary>
    /// General C# Images Functions
    /// </summary>
    public static partial class Images
    {
        /// <summary>
        /// Display Text as Image
        /// </summary>
        /// <param name="linesOfText">Text to Display</param>
        /// <param name="fontSize">Size of Font</param>
        /// <param name="foreground">Text Color</param>
        /// <param name="background">Background Color</param>
        /// <returns></returns>
        public static Bitmap Text(String[] linesOfText, Font font, Color foreground, Color background)
        {
            return Text(String.Join("\n", linesOfText), font, foreground, background);
        }

        /// <summary>
        /// Display Text as Image
        /// </summary>
        /// <param name="text">Text to Display</param>
        /// <param name="fontSize">Size of Font</param>
        /// <param name="foreground">Text Color</param>
        /// <param name="background">Background Color</param>
        /// <returns></returns>
        public static Bitmap Text(String text, Font font, Color foreground, Color background)
        {
            Bitmap img = new Bitmap(10, 10);
            Graphics g = Graphics.FromImage(img);
            g.Clear(background);
            g.DrawString(text.ToString(), font, new SolidBrush(foreground), 0, 0);
            SizeF size = g.MeasureString(text.ToString(), font);
            return img.Clone(new Rectangle(0, 0, (Int32)size.Width, (Int32)size.Height), PixelFormat.Undefined);
        }
    }
}
